//
//  LTQTabBarViewController.swift
//  WeiBoProject
//
//  Created by MAC on 16/2/24.
//  Copyright © 2016年 LTQ. All rights reserved.
//

import UIKit

class LTQTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        let tabbar = LTQTabBar()
        //系统tabBar为readonly属性
        //        self.tabBar = tabBar
        //我们可以采用KVC来修改
        setValue(tabbar, forKey: "TabBar")
        
        
        tabbar.composeButton.addTarget(self, action: "publishWeiBo", forControlEvents: UIControlEvents.TouchUpInside)
        
        addChildViewController()
        
    }
    
    func publishWeiBo() {
        
//        let publishViewController = LTQPublishViewController()
        let nav = UINavigationController(rootViewController: LTQPublishViewController())
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
        
    }
    
    
    func addChildViewController() {
        
        addChildViewController(LTQHomeViewController(), title: "首页", image:
            "tabbar_home")
        addChildViewController(LTQFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(LTQMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(LTQSettingViewController(), title: "设置", image: "tabbar_profile")
    }
    
    
    func addChildViewController(childController: UIViewController,title: String,image: String) {
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: image)
        
//        根据图片名称拼接就可以了，减少了一个参数的传递
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
//        调用的是系统的方法，给tabbar添加子控制器，并将子控制器包装成navigationController
        addChildViewController(UINavigationController(rootViewController: childController))
        
        
    }


}
